<?php

/**
 * @autdor aisyah
 * @copyright 2012
 */
 
require_once "../dao/store_dao.php";
require_once "../../config/upload_file.php";
require_once "../../config/paging.php";

require_once "header.php";

$modul=$_GET['modul'];
$id=$_GET['id'];
$breadcrump ="";

echo "<div class='container'>
<div class='row'>";

switch($modul){
    
    default :
    
        $p = new Paging;
        $batas = 15;
        $posisi = $p->cari_posisi($batas);
        
        echo "
            
            <table class='table table-bordered'>
                <tr><td colspan=6><a href='store_view.php?modul=tambah'><image src='../images/add.png'></a></td></tr>
                <th>ID</th><th>NAMA TOKO</th><th>LOGO</th><th>AKSI</th>
                ";
        $toko = new Store_Dao($class_db);
        
        $toko->get_store(null,$posisi,$batas);       
        
        $data = $toko->store;
        
        if($data!=null) {
            
           foreach($data as $store) {            
            
            echo "
                <tr valign = top>
                    <td>$store->store_id</td>
                    <td><a href='store_view.php?modul=detil&id=$store->store_id'>$store->store_name</a></td>                                        
                    <td><image src='../../images/store/$store->logo'></td>                    
                    <td><a href='store_view.php?modul=ubah&id=$store->store_id'><image src='../images/edit.gif'></a> | 
                        <a href='store_aksi.php?modul=hapus&id=$store->store_id'><image src='../images/delete.gif'></a></td>
                </tr>
                ";        
            
            } 
        }else{
            echo "<tr><td colspan=5 align=center>DATA TIDAK DITEMUKAN</td></tr>";
        }
        
        //print_r($data);        {
        
        
        
         
        echo "            
            </table>
            ";
        $toko->store = null;
        
        $toko->get_store();
            
        $jmldata = count($toko->store);
        
        $jml_halaman = $p->jml_halaman($jmldata,$batas);
        //print_r($jml_halaman);
        
        $link_halaman = $p->navHalaman($modul,$_GET['halaman'],$jml_halaman);
        
        echo $link_halaman;
        
        
    break;    
    
    case "ubah":
    
        $toko = new Store_Dao($class_db);
        
        $toko->get_store($id);
        
        $store = $toko->store;
        
        foreach($store as $data) {            
        
        echo "
            <form method='POST' action='store_aksi.php?modul=ubah' enctype='multipart/form-data'>
            <input type='hidden' name='id' value=$data->store_id>
            <table>
                <tr><td colspan=8 align='center'><h1>Ubah Data Toko</h1></td></tr>
					<tr><td>Nama Toko</td><td><input type='text' name='store_name' value='$data->store_name'></td></tr>
					<tr><td>Deskripsi</td><td><textarea name='description' row=4 col=20>$data->description</textarea></td></tr>
					<tr><td>Alamat :</td><td></td></tr>
                    <tr><td>Jalan</td><td><input type='text' name='street' value='$data->street'></td></tr>
                    <tr><td>Kecamatan</td><td><input type='text' name='kecamatan' value='$data->kecamatan'></td></tr>
                    <tr><td>Provinsi </td><td><select name=province>";
                
                    //<input type=text name=city value=$city>
                    $toko->db->hasil="";
                    $toko->db->show_Data('t_province');
                    $province2 = $toko->db->hasil;
                    //print_r($prov);
                    foreach($province2 as $hasil){
                        if($hasil['province_id']==$data->province){
                            echo "<option value=$hasil[province_id] selected>$hasil[name]</option>";
                        }else{
                            echo "<option value=$hasil[province_id]>$hasil[name]</option>";
                        }
                    }
                    
                    echo "</select></td></tr>
                    <tr><td>Kota </td><td><select name=city>";
                    
                    //<input type=text name=city value=$city>
                    $toko->db->hasil="";
                    $toko->db->show_Data('t_city','*',null,null,'province_id='.$data->province);
                    $city2 = $toko->db->hasil;
                    //print_r($prov);
                    foreach($city2 as $hasil){
                        if($hasil['city_id']==$data->city){
                            echo "<option value=$hasil[city_id] selected>$hasil[city_name]</option>";
                        }else{
                            echo "<option value=$hasil[city_id]>$hasil[city_name]</option>";
                        }
                    }
                    
                    echo "</select></td></tr>
                    <tr><td>Kode Pos</td><td><input type='text' name='zip_code' value=$data->zip_code></td></tr>
                    <tr><td>Logo</td><td><image src='../../images/store/$data->logo'></td></tr>
                    <tr><td></td><td><input type='file' name='logo' value='logo'></td></tr>
                    <tr><td>Gambar Profil</td><td><image src='../../images/store/$data->image'></td></tr>
                    <tr><td></td><td><input type='file' name='image'></td></tr>
                    <tr><td colspan=2><input class='btn btn-primary' type=submit value=Simpan><input class='btn btn-primary' type=button value=Batal onclick=self.history.back()></td></tr>
				</table>
            </form>
            ";
            
            }
    
    break;
    
    case "detil":
    
        $toko = new Store_Dao($class_db);
        
        $toko->get_store($id);
        
        $store = $toko->store;
        
        foreach($store as $data) {
            
            $toko->db->hasil = "";
            $toko->db->show_Data('t_city','city_name',null,null,' city_id='.$data->city);
            $hasil = $toko->db->hasil;
            
            foreach($hasil as $city){
                $city = $city['city_name'];
            }
            
            $toko->db->hasil = "";
            $toko->db->show_Data('t_province','name',null,null,' province_id='.$data->province);
            $hasil = $toko->db->hasil;
            
            foreach($hasil as $province){
                $province = $province['name'];
            }
            
            echo "
            <table>
                <tr><td colspan=8 align='center'><h1>Data Toko</h1></td></tr>
					<tr><td>Nama Toko</td><td>$data->store_name</td></tr>
					<tr><td>Deskripsi</td><td>$data->description</td></tr>
					<tr><td>Alamat :</td><td></td></tr>
                    <tr><td>Jalan</td><td>$data->street</td></tr>
                    <tr><td>Kecamatan</td><td>$data->kecamatan</td></tr>
                    <tr><td>Kota</td><td>$city</td></tr>
                    <tr><td>Propinsi</td><td>$province</td></tr>
                    <tr><td>Kode Pos</td><td>$data->zip_code</td></tr>
                    <tr><td>Logo</td><td><image src=$data->logo></td></tr>
                    <tr><td>Gambar Profil</td><td><image src=$data->image></td></tr>
                    <tr><td colspan=2><input type=button class='btn btn-primary' value='UBAH' onclick=\"window.location.href='store_view.php?modul=ubah&id=$data->store_id';\"><input class='btn btn-primary' type=button value=Kembali onclick=self.history.back()></td></tr>
				</table>
            ";
            
            }
    
    break;
    
echo "</div></div>";
   
}